
$(function(){
	
	var baseUrl = $("base").attr("href");
	var curPage = 1;
	var pageSize = 5;
	var maxSize = 0;
	
	var $_checkNode;
	
	
	/** 请求数据列表显示在table中 开始  */
	
	function loadData(){
		$.ajax({
		type:"post",
		url: baseUrl + "admin/json-getPageEstateBaisicInfo.do",
		async:true,
		data:{pageSize:pageSize,pageNum:curPage,checkState:"待审核"},
		success:function(data){
			if(data.code == 1000){
				$("section table tbody").html("");
				console.log("estateInfoList",data);
				estatInfos = JSON.parse(data.data);
				var i=0;
				if(estatInfos.length > 0){
					maxSize = curPage;
				}else{
					$(".next").addClass("disabled");
					return;
				}
				for ( i; i < estatInfos.length; i++) {
					var item = estatInfos[i];
					var htmlStr =   
					"<tr >"+
					"	<td>" + item.id + "</td>"+
					"	<td>"+ item.user.realName +"</td>"+
					"	<td><span class=\"label label-danger\"><span class=\"glyphicon glyphicon-tags\"></span><span class=\"estateInfoCheckState\">" + item.estateInfoCheckState +"</span></span></td>"+
					"	<td>"+ item.estateType +"</td>"+
					"	<td class=\"btn-group\">"+
					"	<button class=\"btn btn-info\">查看信息</button>"+
					"	<button class=\"btn btn-success\">审核</button>"+
					"	</td>"+
					"	</tr>";
					$(htmlStr).appendTo($("section tbody")).data("estatebasicinfo",item);
				}
			}else{
				console.log("loadDataError",data);
				sweetAlert({
				title:"错误",
				text:"系统错误",
				type:"error",
				timer:2000,
			});
			}
		},
		error:function(){
			sweetAlert({
				title:"错误",
				text:"连接服务器请求数据失败",
				type:"error",
				timer:2000,
			});
			
		}
		
	});
	}
	
	/** 请求数据列表显示在table中 结束  */
	
	/* 动态html事件绑定  开始*/
	$("section table").on("click",".btn-info",function(){
		var basicInfo = $(this).parents("tr").data("estatebasicinfo");
		console.log("estateBasicInfo",basicInfo);
		$(".estateID").eq(0).text(basicInfo.id);
		$("#owner").text(basicInfo.user.realName);
		$("#email").text(basicInfo.user.email);
		$("#tel").text(basicInfo.user.tel);
		$("#certificateId").text(basicInfo.certificateId);
		$("#certificateType").text(basicInfo.certificateType);
		$("#estateAddress").text(basicInfo.estateAddress);
		$("#estateType").text(basicInfo.estateType);
		$("#estateUsingStatue").text(basicInfo.estateUsingStatue);
		$("#structure").text(basicInfo.structure);
		$("#acreage").text(basicInfo.acreage);
		$("#estateDtail").modal("show");
		
	});
	
	$("section table").on("click",".btn-success",function(){
		$_checkNode = $(this).parents("tr");
		var basicInfo = $(this).parents("tr").data("estatebasicinfo");
		$(".estateID").eq(1).text(basicInfo.id);
		
		$("#estateCheck").modal("show");
		$.ajax({
			type:"post",
			url:baseUrl + "commenUtil/json-getListFile.do",
			async:true,
			data:{type:"验证文件",estateInfoId:basicInfo.id},
			success:function(data){
				if(data.code == 1000){
					$("img").attr("src",data.data[0].path)
				}else{
					sweetAlert({
						title:"错误",
						text:"系统错误",
						type:"error",
					});
					console.log("获取文件信息错误",data);
				}
			},
			error:function(){
				sweetAlert({
						title:"错误",
						text:"连接服务器失败",
						type:"error",
					});
			}
		});
	});
	/* 动态html事件绑定  开始*/
	
	/* 翻页  开始 */
	$(".previous").click(function(){
		if(curPage > 1){
			curPage--;
			loadData();
			if(curPage == 1){
				$(this).addClass("disabled");
			}
		}
	});
	
	$(".next").click(function(){
		curPage++
		loadData();
		if(curPage == 2){
			$(".previous").removeClass("disabled");
		}
	});
	
	/* 翻页  结束 */
	
	/* 审核提交 开始 */
	$("#check-submit").click(function(){
		
		$.ajax({
			url: baseUrl + "admin/json-addEstateCheck.do",
			method:"post",
			data:{"estatebasicinfo.id":$(".estateID").eq(1).text(),"checkResult":$("#checkeesult").val(),"remaks":$("textarea").val()},
			success:function(data){
				if(data.code == 1000){
					sweetAlert({
						title:"成功",
						text:"审核信息提交成功",
						type:"success",
						timer:2000,
					});
					$_checkNode.find(".estateInfoCheckState").text(data.data.checkResult);
					$_checkNode.find(".label-danger").removeClass("label-danger").addClass("label-success");
					$_checkNode.find(".btn-success").remove();
				}else{
					sweetAlert({
						title:"错误",
						text:"系统错误",
						type:"error",
					});
					console.log("获取文件信息错误",data);
				}
				
			},
			error:function(){
				sweetAlert({
						title:"错误",
						text:"连接服务器失败",
						type:"error",
					});
			}
		});
		$("#estateCheck").modal("hide");
	});
	/* 审核提交 结束 */
	
	
	
	
	/* 开始操作 */
	
	loadData();
	
});